#include "stdafx.h"
#include "ChangePlanReason.h"
#include "ui_ChangePlanReason.h"
#include "BaseInclude.h"

ChangePlanReason::ChangePlanReason(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::ChangePlanReason)
{
    ui->setupUi(this);
}

ChangePlanReason::ChangePlanReason(QStringList list1, QStringList list2, QStringList list3, QString str1,QString str2, QWidget *parent) :
QDialog(parent),
ui(new Ui::ChangePlanReason)
{
	ui->setupUi(this);
	date = QDateTime::currentDateTime();
	changeTime = date.toString("yyyy-MM-dd HH:MM");
	changePerson = userInfo->getUserName();
	changePersonUnit = userInfo->getCompanyName();
	changePersongDept = userInfo->getDeptName();
	ui->ChangeTimeLineEdit->setText(changeTime);
	ui->ChangePersonDeptLineEdit->setText(changePersongDept);
	ui->ChangePersonLineEdit->setText(changePerson);
	ui->ChangePersonUnitLineEdit->setText(changePersonUnit);

	update_id = str1;
	sheetId = str2;

	uid.Random;
	reasonId = uid.createUuid().toString();
	reasonId = reasonId.replace("{", "");
	reasonId = reasonId.replace("}", "");
	reasonId = reasonId.replace("-", "");

	QStringList newList = list1;
	QStringList oldList = list2;
	QStringList nameList = list3;
	if (nameList.count() == newList.count())
	{
		for (int i = 0; i < nameList.count();i++)
		{
			QString str = QString("[%1]you[%2]gaiwei[%3]").arg(nameList.at(i)).arg(oldList.at(i)).arg(newList.at(i));
			str = str.append(";");
			changeContent.append(str);
		}
		ui->ChangeContentTextEdit->setPlainText(changeContent);
	}

}

ChangePlanReason::~ChangePlanReason()
{
    delete ui;
}

void ChangePlanReason::on_SaveButton_clicked()
{
	changeReason = ui->ChangeReasonTextEdit->toPlainText();
	if (changeReason == NULL)
	{
		qMsgBoxAlert(tr("qingtianxiexiugaiyuanyin"));
		return;
	}
	QString sql;
	sql = QString("insert into jxd_tdjh_update_reason  (REASON_ID,UPDATE_ID,TDJH_ID,UPDATE_CONTENT,UPDATE_REASON,UPDATE_DATE,UPDATE_USERID,UPDATE_USERNAME,UPDATE_ORGID,UPDATE_ORGNAME\
		, UPDATE_DEPTID, UPDATE_DEPT) values('%1', '%2', '%3', '%4', '%5', '%6', '%7', '%8', '%9', '%10', '%11', '%12')")
		.arg(reasonId).arg(update_id).arg(sheetId).arg(changeContent).arg(changeReason).arg(changeTime).arg(changePersonId).arg(changePerson).arg(changePersonUnitId).arg(changePersonUnit).arg(changePersongDeptId).arg(changePersongDept);
	execSQL(sql);

	ui->ChangeReasonTextEdit->setEnabled(false);
}

void ChangePlanReason::on_CloseButton_clicked()
{
    this->close();
}
